/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: lz4_decoder.h
 *
 * Purpose: implementation a decoder with lz4 decompress
 *
 * Developer:
 *   wen.gu , 2022-03-04
 *
 * TODO:
 *
 ***************************************************************************/

/******************************************************************************
 **    INCLUDES
 ******************************************************************************/
#ifndef __LZ4_DECODER_H__
#define __LZ4_DECODER_H__

#include <stdint.h>
#include <string>

#include "lz4/lz4.h"
#include "kfa_types.h"
#include "kfa_decoder.h"
/******************************************************************************
 **    MACROS
 ******************************************************************************/
#define LZ4_DEC_OUT_BUF_CNT (2)
/******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/


/******************************************************************************
 **    CLASSES/FUNCTIONS DEFINITIONS
 ******************************************************************************/
class Lz4Decoder: public KfaDecoder
{
public:
    Lz4Decoder();
    ~Lz4Decoder();
public:
    bool setConfigure(KfaDecoderParam& param) override;
    bool decode(const uint8_t* in_data, uint32_t in_size, KfaBuffer& out_buf) override;
private:
    
    void freeOutBuffer();
    void allocOutBuffer(uint32_t buffer_size);
private:
    //uint16_t img_width_ = 0;
    //uint16_t img_height_ = 0;
    bool is_initialzied_ = false;
    LZ4_streamDecode_t* decoder_ = nullptr;

    uint8_t* out_buf_[LZ4_DEC_OUT_BUF_CNT] = {nullptr};
    uint32_t out_size_ = 0;
    uint32_t out_idx_ = 0;

};




#endif /** !__LZ4_DECODER_H__ */

